$(function(){
	$("#password").focus();

    $("#username").focus(function() {
		if($(this).val()=="请输入用户名"){
            $(this).val("");
		}
    }).blur(function(){
        if ($(this).val()== "") {
            $(this).val("请输入用户名");
        }
    });

    $("#password").focus(function() {
        if($(this).val()=="请输入口令"){
        	$(this).attr("type","password");
            $(this).val("");
        }
    }).blur(function(){
        if ($(this).val()== "") {
            $(this).attr("type","text");
            $(this).val("请输入口令");
        }
    });
});
function fnSubmit(){
	var $loginForm = $("#loginForm");
	// easyui form 验证
	var bValidate = $loginForm.form('enableValidation').form('validate');
	// 验证通过
	if (bValidate) {
		// 密码传输进行加密
		document.getElementById('password').value = hex_md5(document.getElementById('password').value);
	}
	return bValidate;
}
function EnterSumbit(e)
{
	var keynum;
	if (window.event) { // IE
		keynum = e.keyCode;
	} else if (e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}

	if (keynum == 13) {
		if (fnSubmit()) {
			login();
		}	
	}
}
function buttonSubmit()
{
	if(fnSubmit()){
		login();
	}
}
function flushYZM()
{
	var yzm = document.getElementById("checkimg");
	yzm.src = contextPath+'/common/yzm/createYzm?t='+Math.random();
}
function login(){
	var userModel = "co";
	if($("#tab_ua").hasClass("cur")){
		userModel = "ua";
	}
	Ajax({
		url: contextPath + "/execLogin",
		isMask : true,
		data: {
			username:$("#username").val(),
			password:$("#password").val(),
			userModel:userModel
		},
		success: function (data) {
			if (data.success) {
				apexLayer.Msg("登录成功",500,function(){
					window.self.location = contextPath+'/console/index/main';
				});
			} else {
				$("#password").val("");
				apexLayer.Error(data.note,null,false,1000);
			}
		}
	});
}
window.onload = function(){
	var user = document.getElementById('username');
	if (user.value.length<=0) 
		user.focus();
	else
		document.getElementById('password').focus();
}